package com.txsj.scan.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.txsj.scan.R;
import com.txsj.scan.bean.CompanyBean;
import com.txsj.scan.utils.glide.GlideImgManager;

import java.util.ArrayList;
import java.util.List;

/**
 * @Created by WangChuangJun on 2019/2/20
 * @Describe
 */
public class SelectCompanyAdapter extends RecyclerView.Adapter<SelectCompanyAdapter.SelectCompanyHolder> {

    private Context context;
    private List<CompanyBean> list;

    public SelectCompanyAdapter(Context context) {
        this.context = context;
        list = new ArrayList<>();
    }

    public void setList(List<CompanyBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    public List<CompanyBean> getList() {
        return list;
    }

    @Override
    public SelectCompanyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new SelectCompanyHolder(LayoutInflater.from(context).inflate(R.layout.select_company,parent,false));
    }

    @Override
    public void onBindViewHolder(SelectCompanyHolder holder, final int position) {
        CompanyBean bean = list.get(position);
        GlideImgManager.getLoadCircleImg(context,bean.getLogo(),holder.iv_logo);
        holder.tv_boss_name.setText(bean.getBrandName());
        holder.tv_phone_position.setText(bean.getUserName() +" | " +bean.getRole());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != listener)listener.onClick(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class SelectCompanyHolder extends RecyclerView.ViewHolder{

        ImageView iv_logo;
        TextView tv_boss_name,tv_phone_position;


        public SelectCompanyHolder(View itemView) {
            super(itemView);
            iv_logo = (ImageView) itemView.findViewById(R.id.iv_logo);
            tv_boss_name = (TextView) itemView.findViewById(R.id.tv_boss_name);
            tv_phone_position = (TextView) itemView.findViewById(R.id.tv_phone_position);
        }
    }

    private OnClickListener listener;
    public void setListener(OnClickListener listener) {
        this.listener = listener;
    }

    public interface OnClickListener {
        void onClick(int position);
    }
}
